package com.wfh.mianshiji.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wfh.mianshiji.common.BaseResponse;
import com.wfh.mianshiji.common.ErrorCode;
import com.wfh.mianshiji.common.ResultUtils;
import com.wfh.mianshiji.exception.BusinessException;
import com.wfh.mianshiji.model.dto.conversion.ConversionQueryRequest;
import com.wfh.mianshiji.model.vo.ConversionVo;
import com.wfh.mianshiji.service.ConversionService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Title: ConversionController
 * @Author wangfenghuan
 * @Package com.wfh.mianshiji.controller
 * @Date 2025/11/2 17:20
 * @description:
 */
@RestController
@RequestMapping("/conversion")
public class ConversionController {

    @Resource
    private ConversionService conversionService;

    /**
     * 流式游标分页查询对话历史记录
     *
     * @param conversionQueryRequest
     * @param request
     * @return
     */
    @PostMapping("/page")
    public BaseResponse<Page<ConversionVo>> getConversionByPage(@RequestBody ConversionQueryRequest conversionQueryRequest, HttpServletRequest request) {
        Long userId = conversionQueryRequest.getUserId();
        Long interviewId = conversionQueryRequest.getInterviewId();
        String messageType = conversionQueryRequest.getMessageType();
        long pageSize = conversionQueryRequest.getPageSize();
        long current = conversionQueryRequest.getCurrent();
        if (ObjectUtils.allNotNull(userId, interviewId, messageType, pageSize, current)) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        Page<ConversionVo> conversionVoPage = conversionService.getConversionPage(conversionQueryRequest, request);
        return ResultUtils.success(conversionVoPage);
    }

}
